package com.example.qxfw.rcyw.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.qxfw.common.entity.yj.ImpWeatherMoniInfo;
import com.example.qxfw.rcyw.mapper.ImpWeatherMoniInfoMapper;
import com.example.qxfw.rcyw.service.ImpWeatherMoniInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;

@Service
public class ImpWeatherMoniInfoServiceImpl implements ImpWeatherMoniInfoService {

    @Autowired
    private ImpWeatherMoniInfoMapper impWeatherMoniInfoMapper;

    @Override
    public List<ImpWeatherMoniInfo> getMonitorWeather(Integer impHour) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.HOUR_OF_DAY, calendar.get(Calendar.HOUR_OF_DAY) - impHour);
        Timestamp warningTime = Timestamp.valueOf(sdf.format(calendar.getTime()));
        LambdaQueryWrapper<ImpWeatherMoniInfo> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.ge(ImpWeatherMoniInfo::getWarningtime,warningTime).eq(ImpWeatherMoniInfo::getIsremoved,0).orderByDesc(ImpWeatherMoniInfo::getWarningtime);
        List<ImpWeatherMoniInfo> impWeatherMoniInfos = impWeatherMoniInfoMapper.selectList(queryWrapper);
        return impWeatherMoniInfos;
    }
}
